#ifndef COMMON_H_
#define COMMON_H_

#include "WProgram.h"
#include "wiring.h"
#include <stdlib.h>
#include <avr/io.h>
#include "avr/interrupt.h"
#include "motor.h"
#include "encoder.h"
#include "pid.h"
#include "wire.h"


#define Disable_Interrupt()    asm volatile ("cli"::)
#define Enable_Interrupt()     asm volatile ("sei"::)


#define MOTORBOARDADDRESS 1

/*
 * CONSTANTS
 */
#define SERIAL_BAUD_RATE 57600

/*
 * DEBUG ON/OFF
 */
#define DEBUG_ALL 0
#define DEBUG_ERROR 0
#define DEBUG_RADIO 0

/*
 * PID CONSTANTS
 */
#define main_pid_p_gain 			12
#define main_pid_i_gain 	    	0
#define main_pid_d_gain 			6
#define main_pid_i_error_limit 		20
#define main_pid_output_limit 		0
#define main_pid_max_commanded_value	519
#define main_pid_min_commanded_value	0
#define main_start					519

#define jib_pid_p_gain 				12
#define jib_pid_i_gain 	    		0
#define jib_pid_d_gain 				6
#define jib_pid_i_error_limit 		20
#define jib_pid_output_limit 		0
#define jib_pid_max_commanded_value	1416
#define jib_pid_min_commanded_value	0
#define jib_start					1416

#define rudder_pid_p_gain 			80
#define rudder_pid_i_gain 	    	4
#define rudder_pid_d_gain 			2
#define rudder_pid_i_error_limit 	180
#define rudder_pid_output_limit 	0
#define rudder_pid_max_commanded_value	240		//512 + 90
#define rudder_pid_min_commanded_value	0		//512 - 90
#define rudder_start				120

/*
 * MOTOR/ENCODER DEFINITIONS
 */
//main MOTOR
#define main_IN1  2
#define main_IN2  3
#define main_PWM  9
#define main_pwm_duty_deadband 25
//main encoder
#define main_CHA 7					//reversed to correct for motor connection reversal
#define main_CHB 6
#define main_scale_factor 0			//encoder_position>>main_scale_factor


//jib MOTOR
#define jib_IN1  4
#define jib_IN2  5
#define jib_PWM  10
#define jib_pwm_duty_deadband 25
//jib encoder
#define jib_CHA 15
#define jib_CHB 14					//PCINT10
//#define jib_CHA 16
//#define jib_CHB 17					//PCINT10
#define jib_scale_factor 0			//encoder_position>>main_scale_factor

//rudder MOTOR
#define rudder_IN1  16
#define rudder_IN2  17
//#define rudder_IN1  14
//#define rudder_IN2  15
#define rudder_PWM  11
#define rudder_pwm_duty_deadband 25
//rudder encoder
#define rudder_CHA 13
#define rudder_CHB 12
#define rudder_scale_factor 2			//encoder_position>>main_scale_factor

/*************************
 * ANALOG INPUT PINS
 *************************/

/**********************
 * HELPER FUNCTIONS
 **********************/
void debug(const char *fmt, ...);
void error(const char *fmt, ...);
void initDebug(void);



#endif /* COMMON_H_ */
